package com.ruoyi.web.controller.system;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.framework.web.util.MateUtils;
import com.ruoyi.framework.web.util.SendMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.RegisterBody;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.SysRegisterService;
import com.ruoyi.sys.vehile.service.ISysConfigService;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * 注册验证
 *
 * @author ruoyi
 */
@RestController
public class SysRegisterController extends BaseController
{
    @Autowired
    private SysRegisterService registerService;

    @Resource
    RedisTemplate<String,Object> redisTemplate;



    @Autowired
    private ISysConfigService configService;

    @PostMapping("/register")
    public AjaxResult register(@RequestBody RegisterBody user) {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
        {
            return error("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }

    @PostMapping("/phonecode")
    public void phone(@RequestBody Object code){
        System.out.println(code.toString());
        String abc = code.toString();
        MateUtils mateUtils = new MateUtils();
//        String code1 = mateUtils.generateOne(5);
//        redisTemplate.opsForValue().set(abc,code1,120,TimeUnit.SECONDS);
//        new SendMessage().sendMessage(abc,code1);
        System.out.println(redisTemplate.opsForValue().get(abc));
    }
}
